Skip to content

[dsv4] kv cache fp8#1600

Merged
valarLip merged 9 commits into
ROCm:mainfrom
amd-ruitang3:dsv4_kvcache_fp8
Jul 17, 2026
Merged

[dsv4] kv cache fp8#1600
valarLip merged 9 commits into
ROCm:mainfrom
amd-ruitang3:dsv4_kvcache_fp8

Conversation

@amd-ruitang3

Copy link
Copy Markdown
Contributor

Motivation

Technical Details

Test Plan

Test Result

Submission Checklist

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every eligible PR before approval:

  • ✅ Pre Checkin: Black, Ruff, catalog schema validation, non-GPU unit tests

Heavy model tests:

  • ✅ Run after the PR is approved and Pre Checkin passes
  • ✅ Run immediately when an approval review is submitted
  • ✅ Can be requested before approval with labels
Label Tests
ci:full Run all heavy PR model tests: native ATOM, vLLM, and SGLang
ci:atom Run native ATOM model accuracy tests
ci:vllm Run ATOM vLLM OOT model accuracy tests
ci:sglang Run ATOM SGLang model accuracy tests

Heavy jobs are skipped when the PR is not approved and no matching ci:* label is present.
Add labels via the sidebar or gh pr edit 1600 --add-label <label>

@zufayu
zufayu requested a review from jiayyu July 15, 2026 02:20

@ZhangLirong-amd ZhangLirong-amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approve for running ci

"""[padded_T+1] int32 GPU — per-token q indptr `arange(N+1)` (page_size=1,
max_seqlen_q=1). NOT `cu_seqlens_q` (which is per-seq and differs under
MTP); this is the per-token indptr the decode kernel consumes."""
kv_last_page_lens: Optional[torch.Tensor] = None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need these two

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asm decode kernel need them, so I builder them in metadata to aviod redundant opertaion at the layer level.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update metadata once kernel update.

self._rope_dtype = torch.bfloat16 # rope pool is always bf16
# aiter prefill (op4) / decode (op5) support gfx950 (MI350) and
# gfx1250 (MI450) for the fp8 (2buff) path.
assert get_gfx() in ("gfx950", "gfx1250"), (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not support fallback to bf16, just same as what we have before this PR

@amd-ruitang3 amd-ruitang3 Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.

# region is self-consistent (qo_indptr[:N+1] == arange(N+1), kv_indptr[:N+1]
# is the real ragged cumsum) and the dropped tail is exactly the 0-length
# CG-padded slots. No-op when captured/padded (N == T_pad).
qo_indptr = qo_indptr[: N + 1].to(torch.int32)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove these useless .to()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

# path leaves it in logits[:, 0]. logits.shape[1] = resolved split count.
resolved_splits = logits.shape[1]
if out_16_nosplit != 0 or resolved_splits > 1:
return output.to(torch.bfloat16)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an output guard mechanism. We can either adopt output guards or restrict input parameters of the interface.
Root cause: user set “out_16_nosplit=0 && resolved_splits==1”

Comment thread atom/models/deepseek_v4.py Outdated
# and op5 (decode) consume directly — no torch quant, no in-kernel SWA
# scatter.
q_packed = q_rope_q = k_packed = k_rope = None
if self.kv_fp8:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge these 2 path into 1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unify the interface for BF16 and FP8.

Comment thread atom/models/deepseek_v4.py Outdated
self.attn_sink,
self.softmax_scale,
) # [S, H, head_dim]
if self.kv_fp8:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need merge

Comment thread atom/models/deepseek_v4.py Outdated
# after this call and this avoids an extra empty_like allocation.
out=q_sa,
) # [S, H, head_dim]
if self.kv_fp8:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Comment thread atom/models/deepseek_v4.py Outdated
swa_block_size,
min(self.window_size, attn_md.max_seqlen_q),
)
if self.kv_fp8:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@valarLip
valarLip merged commit 8a575ac into ROCm:main Jul 17, 2026
33 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants